package controller.pub;

import controller.MyCoolServlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import model.User;
import persistence.user.UserDAO;
import persistence.user.UserPersistFactory;

public class ReadUserServlet extends MyCoolServlet {

    @Override
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        UserDAO persistenceManager = UserPersistFactory.getUserDAO(persistenceMechanism);
        String name = request.getParameter("userName");
        User user = persistenceManager.readUser(name);
        if (user != null) {
            request.setAttribute("user", user);
            gotoURL(displayUserForm, request, response);
        } else {
            request.setAttribute("message1", "Error al mostrar usuario:");
            request.setAttribute("message2", "Es posible que no exista o que haya sido dado de baja");
            gotoURL(errorForm, request, response);
        }
    }
}
